/**
 * 
 */
package com.swg.cocobox.message.internal;

import java.nio.charset.Charset;

import com.swg.cocobox.message.BroadcastMessage;
import com.swg.cocobox.message.MessageContext;

/**
 * @author satriaprayoga
 *
 */
final class BroadcastMessageImpl implements BroadcastMessage{
	private static final long serialVersionUID = 5615374854764913548L;

	private String origin;
	private String content;
	
	private Charset encoding;
	
	public BroadcastMessageImpl(String origin, String content, Charset encoding) {
		super();
		this.origin = origin;
		this.content = content;
		this.encoding = encoding;
	}

	@Override
	public String getOrigin() {
		return origin;
	}

	@Override
	public String getContent() {
		return content;
	}

	@Override
	public int getMode() {
		return MessageContext.BROADCAST;
	}

	@Override
	public byte[] getBytes() {
		byte[] data=null;
		StringBuilder builder=new StringBuilder();
		builder.append("{origin:"+getOrigin()+"}");
		builder.append("{destination:}");
		builder.append("{content:"+getContent()+"}");
		builder.append("{mode:"+MessageContext.BR+"}");
		data=builder.toString().getBytes(encoding);
		return data;
	}

}
